#include "MeshAssemblyDialog.h"
#include "ui_MeshAssemblyDialog.h"

#include "GUIFrame/MainWindow.h"
#include "FITK_Kernel/FITKAppFramework/FITKAppFramework.h"
#include "FITK_Kernel/FITKAppFramework/FITKSignalTransfer.h"
#include "FITK_Kernel/FITKAppFramework/FITKGlobalData.h"
#include "OperatorsInterface/ParaWidgetInterfaceOperator.h"
#include "FITK_Interface/FITKInterfaceMesh/FITKUnstructuredMeshVTK.h"

#include <vtkSmartPointer.h>
#include <vtkAppendFilter.h>
#include <vtkUnstructuredGrid.h>

#include <QVBoxLayout>
#include <QSpacerItem>
#include <QMessageBox>

namespace GUI
{
    MeshAssemblyDialog::MeshAssemblyDialog(EventOper::ParaWidgetInterfaceOperator * oper, Interface::FITKUnstructuredMeshVTK* obj) :
        Core::FITKWidget(dynamic_cast<MainWindow*>(FITKAPP->getGlobalData()->getMainWindow())), _oper(oper), _obj(obj)
    {
        _ui = new Ui::MeshAssemblyDialog();
        _ui->setupUi(this);

        connect(_ui->pushButton,SIGNAL(clicked(bool)),this,SLOT(AutoInstallset()));
        connect(_ui->pushButton_2,SIGNAL(clicked(bool)),this,SLOT(MovingMould()));
        init();
    }

    MeshAssemblyDialog::~MeshAssemblyDialog()
    {
        if (_ui) {
            delete _ui;
            _ui = nullptr;
        }
    }

    void MeshAssemblyDialog::init()
    {
        // 初始化网格数目
        _manager = _obj->getBoundaryMeshManager();
        for (int i = 0; i < _manager->getDataCount(); i++) {
            Interface::FITKUnstructuredMeshVTK* boundMesh = _manager->getDataByIndex(i);
            QString startname = boundMesh->getDataObjectName();
            _ui->comboBox->addItem(startname);
        }

    }

    void MeshAssemblyDialog::MovingMould()
    {
        QString mode = _ui->comboBox->currentText();
        Interface::FITKUnstructuredMeshVTK* Mesh = _manager->getDataByName(mode);
        if (Mesh == nullptr){
            QMessageBox::warning(this, tr("Warning"), tr("please setting %1 first !").arg(mode));
            return;
        }
        vtkUnstructuredGrid* Meshung = Mesh->getGrid();
        vtkPoints* Meshpoints = Meshung->GetPoints();
        const int Meshnodesum = Meshpoints->GetNumberOfPoints();
        if(Meshnodesum == 0)return;

        double x = _ui->doubleSpinBoxX->value();
        double y = _ui->doubleSpinBoxY->value();
        double z = _ui->doubleSpinBoxZ->value();
        moveMesh(Meshnodesum,Meshpoints,Meshung,x,y,z);

        _oper->execProfession();
        emit sigAssemblyFinish();
    }

    void MeshAssemblyDialog::AutoInstallset()
    {
        if(_ui->Type->currentText() == "SingleCoin"){
            bool OK = AutoInstallset_SingleCoin();
            if(!OK){
                emit FITKAPP->getSignalTransfer()->outputMessageSig(3, tr("Warning :  SingleCoin Assembly failed !!! "));
                return;
            }
            _oper->execProfession();
            emit sigAssemblyFinish();
        }else if(_ui->Type->currentText() == "TwoCoins"){
            bool OK = AutoInstallset_TwoCoins();
            if(!OK){
                emit FITKAPP->getSignalTransfer()->outputMessageSig(3, tr("Warning :  TwoCoins Assembly failed !!! "));
                return;
            }
            _oper->execProfession();
            emit sigAssemblyFinish();
        }else if(_ui->Type->currentText() == "Clinching"){
            bool OK = AutoInstallset_Clinching();
            if(!OK){
                emit FITKAPP->getSignalTransfer()->outputMessageSig(3, tr("Warning :  Clinching Assembly failed !!! "));
                return;
            }
            _oper->execProfession();
            emit sigAssemblyFinish();
        }
    }

    bool MeshAssemblyDialog::AutoInstallset_Clinching()
    {
        if(_manager->getDataCount() != 5) {
            QMessageBox::warning(this, tr("Warning"), tr("Please import enough models !"));
            return false;
        }
        Interface::FITKUnstructuredMeshVTK* Punch = _manager->getDataByName("Punch");
        if (Punch == nullptr){
            QMessageBox::warning(this, tr("Warning"), tr("please setting Punch first !"));
            return false;
        }
        Interface::FITKUnstructuredMeshVTK* Lowdie = _manager->getDataByName("Die");
        if (Lowdie == nullptr){
            QMessageBox::warning(this, tr("Warning"), tr("please setting Die first !"));
            return false;
        }
        Interface::FITKUnstructuredMeshVTK* Middle = _manager->getDataByName("BH");
        if (Middle == nullptr){
            QMessageBox::warning(this, tr("Warning"), tr("please setting BH first !"));
            return false;
        }
        Interface::FITKUnstructuredMeshVTK* BottomSheet = _manager->getDataByName("BottomSheet");
        if (BottomSheet == nullptr){
            QMessageBox::warning(this, tr("Warning"), tr("please setting BottomSheet first !"));
            return false;
        }
        Interface::FITKUnstructuredMeshVTK* TopSheet = _manager->getDataByName("TopSheet");
        if (TopSheet == nullptr){
            QMessageBox::warning(this, tr("Warning"), tr("please setting TopSheet first !"));
            return false;
        }


        //求上冲头表面的X、Y、Z中心点坐标
        vtkUnstructuredGrid* Punchung = Punch->getGrid(); //设置此算法上端口的输出数据对象。
        vtkPoints* Punchpoints = Punchung->GetPoints();//获得单元的点坐标
        const int Punchnodesum = Punchpoints->GetNumberOfPoints();//网格的节点总数目
        if(Punchnodesum == 0)return false;

        //求出上冲头节点的坐标X，Y，Z的最大值、最小值liuyun
        double xyzMax_Punch[3] = { -1e10 ,-1e10 ,-1e10 };//设置上模的最大XYZ的值
        double xyzMin_Punch[3] = { 1e10 ,1e10 ,1e10 };//设置上模的最小XYZ的值
        double PunchXYZ[3] = { 1e10 ,1e10 ,1e10 };
        genMeshMaxMinCoordinate(Punchnodesum , Punchpoints , xyzMax_Punch , xyzMin_Punch);
        genMeshCenterPoint(xyzMax_Punch , xyzMin_Punch , PunchXYZ);


        //求下腔表面的X、Y、Z中心点坐标
        vtkUnstructuredGrid* lowdieung = Lowdie->getGrid();
        vtkPoints* lowdiepoints = lowdieung->GetPoints();
        const int lowdienodesum = lowdiepoints->GetNumberOfPoints();
        if(lowdienodesum == 0)return false;

        double xyzMax_low[3] = { -1e10 ,-1e10 ,-1e10 };
        double xyzMin_low[3] = { 1e10 ,1e10 ,1e10 };
        double lowdieXYZ[3] = { 1e10 ,1e10 ,1e10 };
        genMeshMaxMinCoordinate(lowdienodesum , lowdiepoints , xyzMax_low , xyzMin_low);
        genMeshCenterPoint(xyzMax_low , xyzMin_low , lowdieXYZ);


        //求压边圈的X、Y、Z中心点坐标
        vtkUnstructuredGrid* middleung = Middle->getGrid();
        vtkPoints* middlepoints = middleung->GetPoints();
        const int middlenodesum = middlepoints->GetNumberOfPoints();
        if(middlenodesum == 0)return false;

        //求出压边圈节点的坐标X，Y，Z的最大值、最小值
        double xyzMax_middle[3] = { -1e10 ,-1e10 ,-1e10 };
        double xyzMin_middle[3] = { 1e10 ,1e10 ,1e10 };
        double middleXYZ[3] = { 1e10 ,1e10 ,1e10 };
        genMeshMaxMinCoordinate(middlenodesum , middlepoints , xyzMax_middle , xyzMin_middle);
        genMeshCenterPoint(xyzMax_middle , xyzMin_middle , middleXYZ);


        //求下板料的X、Y、Z中心点坐标
        vtkUnstructuredGrid* BottomSheetung = BottomSheet->getGrid();
        vtkPoints* BottomSheetpoints = BottomSheetung->GetPoints();
        const int BottomSheetnodesum = BottomSheetpoints->GetNumberOfPoints();
        if(BottomSheetnodesum == 0)return false;

        double xyzMax_BottomSheet[3] = { -1e10 ,-1e10 ,-1e10 };
        double xyzMin_BottomSheet[3] = { 1e10 ,1e10 ,1e10 };
        double BottomSheetXYZ[3] = { 1e10 ,1e10 ,1e10 };
        genMeshMaxMinCoordinate(BottomSheetnodesum , BottomSheetpoints , xyzMax_BottomSheet , xyzMin_BottomSheet);
        genMeshCenterPoint(xyzMax_BottomSheet , xyzMin_BottomSheet , BottomSheetXYZ);


        //求上板料的X、Y、Z中心点坐标
        vtkUnstructuredGrid* TopSheetung = TopSheet->getGrid();
        vtkPoints* TopSheetpoints = TopSheetung->GetPoints();
        const int TopSheetnodesum = TopSheetpoints->GetNumberOfPoints();
        if(TopSheetnodesum == 0)return false;

        double xyzMax_TopSheet[3] = { -1e10 ,-1e10 ,-1e10 };
        double xyzMin_TopSheet[3] = { 1e10 ,1e10 ,1e10 };
        double TopSheetXYZ[3] = { 1e10 ,1e10 ,1e10 };
        genMeshMaxMinCoordinate(TopSheetnodesum , TopSheetpoints , xyzMax_TopSheet , xyzMin_TopSheet);
        genMeshCenterPoint(xyzMax_TopSheet , xyzMin_TopSheet , TopSheetXYZ);


        //求出上冲头与下板，下腔与下板,压边圈与下板，上板与下板之间的x，y之间的距离
        double x1 = BottomSheetXYZ[0] - PunchXYZ[0];
        double x2 = BottomSheetXYZ[0] - lowdieXYZ[0];
        double x3 = BottomSheetXYZ[0] - middleXYZ[0];
        double x4 = BottomSheetXYZ[0] - TopSheetXYZ[0];
        double y1 = BottomSheetXYZ[1] - PunchXYZ[1];
        double y2 = BottomSheetXYZ[1] - lowdieXYZ[1];
        double y3 = BottomSheetXYZ[1] - middleXYZ[1];
        double y4 = BottomSheetXYZ[1] - TopSheetXYZ[1];

        //求出上板料与下板料之间的Z轴距离
        double d0 = 0; double z0 = 0;
        d0 = xyzMin_TopSheet[2] - xyzMax_BottomSheet[2];
        z0 = -d0;

        //保证上冲头最低点和上板料的最高点位置公差0.000001
        double d1 = 0; double z1 = 0;
        d1 = xyzMin_Punch[2] - xyzMax_TopSheet[2];
        z1 = 0.000001 - d1;
        z1 = z1 + z0;

        //保证下腔最高点和下板料的最低点位置公差0.000001
        double d2 = 0; double z2 = 0;
        d2 = xyzMin_BottomSheet[2] - xyzMax_low[2];
        z2 = d2 - 0.000001;

        //保证压边圈最低点和上板料的最高点位置公差0.000001
        double d3 = 0; double z3 = 0;
        d3 = xyzMin_middle[2] - xyzMax_TopSheet[2];
        z3 = 0.000001 - d3;
        z3 = z3 + z0;

        //对上模进行移动
        moveMesh(Punchnodesum,Punchpoints,Punchung,x1,y1,z1);
        //对下模进行移动
        moveMesh(lowdienodesum,lowdiepoints,lowdieung,x2,y2,z2);
        //对压边圈进行移动
        moveMesh(middlenodesum,middlepoints,middleung,x3,y3,z3);
        //对上板进行移动
        moveMesh(TopSheetnodesum,TopSheetpoints,TopSheetung,x4,y4,z0);

        return true;
    }

    bool MeshAssemblyDialog::AutoInstallset_SingleCoin()
    {
        if(_manager->getDataCount() != 4) {
            QMessageBox::warning(this, tr("Warning"), tr("Please import enough models !"));
            return false;
        }
        Interface::FITKUnstructuredMeshVTK* UpDie = _manager->getDataByName("UpDie");
        if (UpDie == nullptr){
            QMessageBox::warning(this, tr("Warning"), tr("please setting UpDie first !"));
            return false;
        }
        Interface::FITKUnstructuredMeshVTK* LowDie = _manager->getDataByName("LowDie");
        if (LowDie == nullptr){
            QMessageBox::warning(this, tr("Warning"), tr("please setting LowDie first !"));
            return false;
        }
        Interface::FITKUnstructuredMeshVTK* Sheet = _manager->getDataByName("Sheet");
        if (Sheet == nullptr){
            QMessageBox::warning(this, tr("Warning"), tr("please setting Sheet first !"));
            return false;
        }
        Interface::FITKUnstructuredMeshVTK* MidDie = _manager->getDataByName("MidDie");
        if (MidDie == nullptr){
            QMessageBox::warning(this, tr("Warning"), tr("please setting MidDie first !"));
            return false;
        }


        //求上模表面的X、Y、Z中心点坐标
        vtkUnstructuredGrid* updieung = UpDie->getGrid();
        vtkPoints* updiepoints = updieung->GetPoints();
        const int updienodesum = updiepoints->GetNumberOfPoints();
        if(updienodesum == 0)return false;

        //求出上模节点的坐标X，Y，Z的最大值、最小值
        double xyzMax_up[3] = { -1e10 ,-1e10 ,-1e10 };
        double xyzMin_up[3] = { 1e10 ,1e10 ,1e10 };
        double updie[3] = { 1e10 ,1e10 ,1e10 };
        genMeshMaxMinCoordinate(updienodesum , updiepoints , xyzMax_up , xyzMin_up);
        genMeshCenterPoint(xyzMax_up , xyzMin_up , updie);


        //求下模表面的X、Y、Z中心点坐标
        vtkUnstructuredGrid* lowdieung = LowDie->getGrid();
        vtkPoints* lowdiepoints = lowdieung->GetPoints();
        const int lowdienodesum = lowdiepoints->GetNumberOfPoints();
        if(lowdienodesum == 0)return false;

        double xyzMax_low[3] = { -1e10 ,-1e10 ,-1e10 };
        double xyzMin_low[3] = { 1e10 ,1e10 ,1e10 };
        double lowdie[3] = { 1e10 ,1e10 ,1e10 };
        genMeshMaxMinCoordinate(lowdienodesum , lowdiepoints , xyzMax_low , xyzMin_low);
        genMeshCenterPoint(xyzMax_low , xyzMin_low , lowdie);


        //求中圈的X、Y、Z中心点坐标
        vtkUnstructuredGrid* middleung = MidDie->getGrid();
        vtkPoints* middlepoints = middleung->GetPoints();
        const int middlenodesum = middlepoints->GetNumberOfPoints();
        if(middlenodesum == 0)return false;

        //求出中圈节点的坐标X，Y，Z的最大值、最小值
        double xyzMax_middle[3] = { -1e10 ,-1e10 ,-1e10 };
        double xyzMin_middle[3] = { 1e10 ,1e10 ,1e10 };
        double middle[3] = { 1e10 ,1e10 ,1e10 };
        genMeshMaxMinCoordinate(middlenodesum , middlepoints , xyzMax_middle , xyzMin_middle);
        genMeshCenterPoint(xyzMax_middle , xyzMin_middle , middle);


        //求坯饼的X、Y、Z中心点坐标
        vtkUnstructuredGrid* sheetung = Sheet->getGrid();
        vtkPoints* sheetpoints = sheetung->GetPoints();
        const int sheetnodesum = sheetpoints->GetNumberOfPoints();
        if(sheetnodesum == 0)return false;

        double xyzMax_sheet[3] = { -1e10 ,-1e10 ,-1e10 };
        double xyzMin_sheet[3] = { 1e10 ,1e10 ,1e10 };
        double sheet[3] = { 1e10 ,1e10 ,1e10 };
        genMeshMaxMinCoordinate(sheetnodesum , sheetpoints , xyzMax_sheet , xyzMin_sheet);
        genMeshCenterPoint(xyzMax_sheet , xyzMin_sheet , sheet);


        //求出上模与坯饼，下模与坯饼,中圈与坯饼之间的x，y之间的距离
        double x1 = sheet[0] - updie[0];
        double x2 = sheet[0] - lowdie[0];
        double x3 = sheet[0] - middle[0];
        double y1 = sheet[1] - updie[1];
        double y2 = sheet[1] - lowdie[1];
        double y3 = sheet[1] - middle[1];

        //求出坯饼与中圈之间的Z轴距离
        double z = sheet[2] - middle[2];

        //保证上模最低点和坯饼的最高点位置公差0.001
        double d1 = 0; double z1 = 0;
        d1 = xyzMin_up[2] - xyzMax_sheet[2];
        z1 = 0.001 - d1;

        //保证下模最高点和坯饼的最低点位置公差0.001
        double d2 = 0; double z2 = 0;
        d2 = xyzMin_sheet[2] - xyzMax_low[2];
        z2 = d2 - 0.001;

        //对上模进行移动
        moveMesh(updienodesum,updiepoints,updieung,x1,y1,z1);
        //对下模进行移动
        moveMesh(lowdienodesum,lowdiepoints,lowdieung,x2,y2,z2);
        //对中圈进行移动
        moveMesh(middlenodesum,middlepoints,middleung,x3,y3,z);

        return true;
    }

    bool MeshAssemblyDialog::AutoInstallset_TwoCoins()
    {
        if(_manager->getDataCount() != 5) {
            QMessageBox::warning(this, tr("Warning"), tr("Please import enough models !"));
            return false;
        }
        Interface::FITKUnstructuredMeshVTK* UpDie = _manager->getDataByName("UpDie");
        if (UpDie == nullptr){
            QMessageBox::warning(this, tr("Warning"), tr("please setting UpDie first !"));
            return false;
        }
        Interface::FITKUnstructuredMeshVTK* Lowdie = _manager->getDataByName("LowDie");
        if (Lowdie == nullptr){
            QMessageBox::warning(this, tr("Warning"), tr("please setting LowDie first !"));
            return false;
        }
        Interface::FITKUnstructuredMeshVTK* Middle = _manager->getDataByName("MidDie");
        if (Middle == nullptr){
            QMessageBox::warning(this, tr("Warning"), tr("please setting MidDie first !"));
            return false;
        }
        Interface::FITKUnstructuredMeshVTK* Inner = _manager->getDataByName("Inner");
        if (Inner == nullptr){
            QMessageBox::warning(this, tr("Warning"), tr("please setting Inner first !"));
            return false;
        }
        Interface::FITKUnstructuredMeshVTK* Outer = _manager->getDataByName("Outer");
        if (Outer == nullptr){
            QMessageBox::warning(this, tr("Warning"), tr("please setting Outer first !"));
            return false;
        }


        //求上模表面的X、Y、Z中心点坐标
        vtkUnstructuredGrid* updieung = UpDie->getGrid();
        vtkPoints* updiepoints = updieung->GetPoints();
        const int updienodesum = updiepoints->GetNumberOfPoints();
        if(updienodesum == 0)return false;

        double xyzMax_up[3] = { -1e10 ,-1e10 ,-1e10 };
        double xyzMin_up[3] = { 1e10 ,1e10 ,1e10 };
        double updie[3] = { 1e10 ,1e10 ,1e10 };
        genMeshMaxMinCoordinate(updienodesum , updiepoints , xyzMax_up , xyzMin_up);
        genMeshCenterPoint(xyzMax_up , xyzMin_up , updie);


        //求下模表面的X、Y、Z中心点坐标
        vtkUnstructuredGrid* lowdieung = Lowdie->getGrid();
        vtkPoints* lowdiepoints = lowdieung->GetPoints();
        const int lowdienodesum = lowdiepoints->GetNumberOfPoints();
        if(lowdienodesum == 0)return false;

        double xyzMax_low[3] = { -1e10 ,-1e10 ,-1e10 };
        double xyzMin_low[3] = { 1e10 ,1e10 ,1e10 };
        double lowdie[3] = { 1e10 ,1e10 ,1e10 };
        genMeshMaxMinCoordinate(lowdienodesum , lowdiepoints , xyzMax_low , xyzMin_low);
        genMeshCenterPoint(xyzMax_low , xyzMin_low , lowdie);


        //求中圈的X、Y、Z中心点坐标
        vtkUnstructuredGrid* middleung = Middle->getGrid();
        vtkPoints* middlepoints = middleung->GetPoints();
        const int middlenodesum = middlepoints->GetNumberOfPoints();
        if(middlenodesum == 0)return false;

        double xyzMax_middle[3] = { -1e10 ,-1e10 ,-1e10 };
        double xyzMin_middle[3] = { 1e10 ,1e10 ,1e10 };
        double middle[3] = { 1e10 ,1e10 ,1e10 };
        genMeshMaxMinCoordinate(middlenodesum , middlepoints , xyzMax_middle , xyzMin_middle);
        genMeshCenterPoint(xyzMax_middle , xyzMin_middle , middle);


        //求内芯的X、Y、Z中心点坐标
        vtkUnstructuredGrid* innerung = Inner->getGrid();
        vtkPoints* innerpoints = innerung->GetPoints();
        const int innernodesum = innerpoints->GetNumberOfPoints();
        if(innernodesum == 0)return false;

        double xyzMax_inner[3] = { -1e10 ,-1e10 ,-1e10 };
        double xyzMin_inner[3] = { 1e10 ,1e10 ,1e10 };
        double inner[3] = { 1e10 ,1e10 ,1e10 };
        genMeshMaxMinCoordinate(innernodesum , innerpoints , xyzMax_inner , xyzMin_inner);
        genMeshCenterPoint(xyzMax_inner , xyzMin_inner , inner);


        //求外环的X、Y、Z中心点坐标
        vtkUnstructuredGrid* outerung = Outer->getGrid();
        vtkPoints* outerpoints = outerung->GetPoints();
        const int outernodesum = outerpoints->GetNumberOfPoints();
        if(outernodesum == 0)return false;

        double xyzMax_outer[3] = { -1e10 ,-1e10 ,-1e10 };
        double xyzMin_outer[3] = { 1e10 ,1e10 ,1e10 };
        double outer[3] = { 1e10 ,1e10 ,1e10 };
        genMeshMaxMinCoordinate(outernodesum , outerpoints , xyzMax_outer , xyzMin_outer);
        genMeshCenterPoint(xyzMax_outer , xyzMin_outer , outer);


        //求出上模与内芯，下模与内芯,中圈与内芯，内芯与外环之间的x，y之间的距离
        double x1 = inner[0] - updie[0];
        double x2 = inner[0] - lowdie[0];
        double x3 = inner[0] - middle[0];
        double x4 = inner[0] - outer[0];
        double y1 = inner[1] - updie[1];
        double y2 = inner[1] - lowdie[1];
        double y3 = inner[1] - middle[1];
        double y4 = inner[1] - outer[1];

        //求出内芯与中圈，内芯与外环之间的Z轴距离
        double z = inner[2] - middle[2];
        double z0 = inner[2] - outer[2];

        //保证上模最低点和坯饼的最高点位置公差0.01
        double d1 = 0; double z1 = 0;
        d1 = xyzMin_up[2] - xyzMax_inner[2];
        z1 = 0.01 - d1;

        //保证下模最高点和坯饼的最低点位置公差0.001
        double d2 = 0; double z2 = 0;
        d2 = xyzMin_inner[2] - xyzMax_low[2];
        z2 = d2 - 0.001;

        //对上模进行移动
        moveMesh(updienodesum,updiepoints,updieung,x1,y1,z1);
        //对下模进行移动
        moveMesh(lowdienodesum,lowdiepoints,lowdieung,x2,y2,z2);
        //对中圈进行移动
        moveMesh(middlenodesum,middlepoints,middleung,x3,y3,z);
        //对外环进行移动
        moveMesh(outernodesum,outerpoints,outerung,x4,y4,z0);

        return true;
    }

    void MeshAssemblyDialog::genMeshCenterPoint(double* xyzMax,double* xyzMin,double* MeshXYZ)
    {
        MeshXYZ[0] = (xyzMax[0]+xyzMin[0])/ 2;
        MeshXYZ[1] = (xyzMax[1]+xyzMin[1])/ 2;
        MeshXYZ[2] = (xyzMax[2]+xyzMin[2])/ 2;
    }

    void MeshAssemblyDialog::genMeshMaxMinCoordinate(int meshpointnumber,vtkPoints* points,double* xyzMax,double* xyzMin)
    {
        double meshDie[3] = {0.00};
        for (int i = 0; i < meshpointnumber; ++i)
        {
            points->GetPoint(i, meshDie);//通过i节点的ID号获取第i个节点的坐标x,y,z

            if (meshDie[0] > xyzMax[0]) xyzMax[0] = meshDie[0];
            if (meshDie[0] < xyzMin[0]) xyzMin[0] = meshDie[0];
            if (meshDie[1] > xyzMax[1]) xyzMax[1] = meshDie[1];
            if (meshDie[1] < xyzMin[1]) xyzMin[1] = meshDie[1];
            if (meshDie[2] > xyzMax[2]) xyzMax[2] = meshDie[2];
            if (meshDie[2] < xyzMin[2]) xyzMin[2] = meshDie[2];
        }
    }

    void MeshAssemblyDialog::moveMesh(int meshpointnumber,vtkPoints* points,vtkUnstructuredGrid* ung,
                  double x,double y,double z)
    {
        double meshDie[3] = {0.00};
        for (int i = 0; i < meshpointnumber; ++i)
        {
            points->GetPoint(i, meshDie);
            double res[3] = { 0.00 };
            res[0] = x + meshDie[0];
            res[1] = y + meshDie[1];
            res[2] = z + meshDie[2];
            points->SetPoint(i, res);//通过节点i的ID号覆盖新的坐标
        }

        points->Modified();//更新节点及其数据修改的时间
//        mesh->DeepCopy(ung);
//        mesh->Modified();
    }

}

